package com.itboye.eweilisten.util.widget;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.itboye.eweilisten.me.personal.model.PersonDataBean;
import com.itboye.eweilisten.presenter.UserPresenter;
import com.itboye.eweilisten.util.logincontroller.LoginController;
import com.itboye.eweilisten.util.logincontroller.LoginedState;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.sputil.SPUtils;

/**
 * Created by itboye on 2017/3/15.
 * 用于发送广播调用
 */
public class FilterUtil {
    public static String LOGIN = "MeFragment";//登录
    public static String EXITLOGIN = "Exitlogin";//退出登录
    public static String HEAD = "head";

    public static void putSharePre(Context context, PersonDataBean bean) {
        LoginController.setLoginState(new LoginedState());
        SPUtils.put(context, null,
                Const.PaySecret, bean.getPay_secret());
//        SPUtils.put(LoginActivity.this, null,
//                Const.RELE, bean.getRolesInfo().get(0).getGroupId());
        Log.d("toten", bean.getJob_title());
        SPUtils.put(context, null,
                Const.ID, bean.getId());
        SPUtils.put(context, null,
                Const.USERNAME, bean.getUsername());
        SPUtils.put(context, null,
                Const.PASSWORD, bean.getPassword());
        SPUtils.put(context, null,
                Const.MOBILE, bean.getMobile());
        SPUtils.put(context, null,
                Const.IS_LOGINED, true);
        SPUtils.put(context, null,
                Const.HEAD, bean.getHead());
        SPUtils.put(context, null,
                Const.NICK, bean.getNickname());
        SPUtils.put(context, null,
                Const.EMAIL, bean.getEmail());
        SPUtils.put(context, null,
                Const.READE_NAME, bean.getGrade_name());
        SPUtils.put(context, null,
                Const.Andress, bean.getLoc_area());
        SPUtils.put(context, null,
                Const.S_ID, bean.getAuto_login_code());
        SPUtils.put(context, null,
                Const.SEX, bean.getSex());
        SPUtils.put(context, null,
                Const.AUTO_CODE, bean.getAuto_login_code());
        SPUtils.put(context, null,
                Const.SCHOOL_NAME, bean.getLoc_school());

        sendLoginSucceed(context);
    }
    //发送广播登录成功
    public static void sendLoginSucceed(Context context) {
        LoginController.setLoginState(new LoginedState());
        Intent intent = new Intent(FilterUtil.LOGIN);
        context.sendBroadcast(intent);
    }

    public static void onUserPresenter(UserPresenter presenter, String auth_code, String uid, String niceName, String Sex, String nameOPe, String xuewaStrId, String SchoolId, String Andress) {
        if (Sex.equals("男")) {
            Sex = "1";
        } else {
            Sex = "0";
        }
        presenter.onUpdateUser(auth_code, uid, niceName, Sex, "", nameOPe, xuewaStrId, SchoolId, "1", Andress);
    }


}
